package com.atguigu.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;

@WebServlet("/servlet3")
public class Servlet3 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取上传文件的路径
        //String path = "F:\\Java\\project\\javaweb\\out\\artifacts\\demo03_servlerConfig_ServletContext_war_exploded\\upload";
        ServletContext servletContext = getServletContext();
        String path = servletContext.getRealPath("upload");
        System.out.println("path :" + path);
        //FileOutputStream fos = new FileOutputStream(path + "/a.txt");

        //获取项目的上下文路径
        String contextPath = servletContext.getContextPath();
        System.out.println("contextPath :" + contextPath);
    }
}
